package jam.components;

import jam.beans.Driver;
import jam.beans.Location;
import jam.beans.LocationInstance;
import jam.beans.Route;
import jam.beans.Schedule;
import jam.beans.Shuttle;
import jam.beans.Trip;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.atomic.AtomicLong;

import javax.annotation.PostConstruct;

import org.springframework.stereotype.Component;

/**
 * This stubs out a db, and exposes all shuttles, and stuff
 * 
 * @author Kiren.Rawatlal
 *
 */
@Component
public class ShuttleDB {

  private final AtomicLong counter = new AtomicLong();
  

  private static HashMap<String, Shuttle> sbShuttlesMapped = new HashMap<String, Shuttle>();
  private static List<Route> sbRoutes = new ArrayList<Route>();
  private static List<Location> sbDestinationLocations = new ArrayList<Location>();
  private static List<Driver> sbDrivers = new ArrayList<Driver>();
  private static List<Shuttle> sbShuttles = new ArrayList<Shuttle>();

  Location l1_5simmonds = new Location(1, -26.211112, 28.039168);
  Location l2_commisioner = new Location(4, -26.205877, 28.036631);
  Location l3_rosebank = new Location(6, -26.147353, 28.043516);
  Location l4_station = new Location(4, -26.194937, 28.041795);

  Route r1 = new Route("1", "Gautrain Station", l1_5simmonds, l4_station);
  Route r2 = new Route("2", "45 Commissioner", l1_5simmonds, l2_commisioner);
  Route r3 = new Route("3", "Rosebank", l1_5simmonds, l3_rosebank);

  Driver d1 = new Driver("1", "Naruto", "Usumaki");
  Driver d2 = new Driver("2", "Ichigo", "Korusaki");
  Driver d3 = new Driver("3", "Luffy", "Monkey");
  Driver d4 = new Driver("4", "Grey", "Ice");
  Driver d5 = new Driver("4", "Bruce", "Banner");

  Shuttle s1 = new Shuttle("1", "Captain America", 30);
  Shuttle s2 = new Shuttle("2", "Hulk", 30);
  Shuttle s3 = new Shuttle("3", "Scarlett MMMmmm", 20);
  Shuttle s4 = new Shuttle("4", "Ironman", 20);
  Shuttle s5 = new Shuttle("5", "Agent Simmons", 50);

  // String driverId, Date time, Location location, String shuttleId, String routeId
  LocationInstance sp1 = new LocationInstance(d1.getId(), new Date(), l1_5simmonds, s1.getId(), r1.getId(), true, true);
  LocationInstance sp2 = new LocationInstance(d2.getId(), new Date(), l4_station, s2.getId(), r1.getId(), true, true);
  LocationInstance sp3 = new LocationInstance(d3.getId(), new Date(), l1_5simmonds, s3.getId(), r2.getId(), true, true);
  LocationInstance sp4 = new LocationInstance(d4.getId(), new Date(), l2_commisioner, s4.getId(), r2.getId(), true, true);
  LocationInstance sp5 = new LocationInstance(d5.getId(), new Date(), l1_5simmonds, s5.getId(), r3.getId(), true, true);

  @PostConstruct
  private void loadData() {

    sbDestinationLocations.add(l1_5simmonds);
    sbDestinationLocations.add(l2_commisioner);
    sbDestinationLocations.add(l3_rosebank);
    sbDestinationLocations.add(l4_station);

    s1.setLatestLocation(sp1);
    s2.setLatestLocation(sp2);
    s3.setLatestLocation(sp3);
    s4.setLatestLocation(sp4);
    s5.setLatestLocation(sp5);

    sbShuttlesMapped.put(s1.getId(), s1);
    sbShuttlesMapped.put(s2.getId(), s2);
    sbShuttlesMapped.put(s3.getId(), s3);
    sbShuttlesMapped.put(s4.getId(), s4);
    sbShuttlesMapped.put(s5.getId(), s5);

    sbShuttles.add(s1);
    sbShuttles.add(s2);
    sbShuttles.add(s3);
    sbShuttles.add(s4);
    sbShuttles.add(s5);

    sbDrivers.add(d1);
    sbDrivers.add(d2);
    sbDrivers.add(d3);
    sbDrivers.add(d4);
    sbDrivers.add(d5);

    Schedule sc1 = new Schedule();
    sc1.getTrips().add(new Trip("06:00", "06:10", "06:15", "06:25"));
    sc1.getTrips().add(new Trip("06:00", "07:10", "07:15", "07:25"));
    sc1.getTrips().add(new Trip("08:00", "08:10", "08:15", "08:25"));
    sc1.getTrips().add(new Trip("09:00", "09:10", "09:15", "09:25"));

    r1.setSchedule(sc1);
    r2.setSchedule(sc1);
    r3.setSchedule(sc1);

    sbRoutes.add(r1);
    sbRoutes.add(r2);
    sbRoutes.add(r3);

  }
  

  public static HashMap<String, Shuttle> getSbShuttlesMapped() {
    return sbShuttlesMapped;
  }

  public static void setSbShuttlesMapped(HashMap<String, Shuttle> sbShuttlesMapped) {
    ShuttleDB.sbShuttlesMapped = sbShuttlesMapped;
  }

  public static List<Route> getSbRoutes() {
    return sbRoutes;
  }

  public static void setSbRoutes(List<Route> sbRoutes) {
    ShuttleDB.sbRoutes = sbRoutes;
  }

  public static List<Location> getSbDestinationLocations() {
    return sbDestinationLocations;
  }

  public static void setSbDestinationLocations(List<Location> sbDestinationLocations) {
    ShuttleDB.sbDestinationLocations = sbDestinationLocations;
  }

  public static List<Driver> getSbDrivers() {
    return sbDrivers;
  }

  public static void setSbDrivers(List<Driver> sbDrivers) {
    ShuttleDB.sbDrivers = sbDrivers;
  }

  public static List<Shuttle> getSbShuttles() {
    return sbShuttles;
  }

  public static void setSbShuttles(List<Shuttle> sbShuttles) {
    ShuttleDB.sbShuttles = sbShuttles;
  }

  public Location getL1_5simmonds() {
    return l1_5simmonds;
  }

  public void setL1_5simmonds(Location l1_5simmonds) {
    this.l1_5simmonds = l1_5simmonds;
  }

  public Location getL2_commisioner() {
    return l2_commisioner;
  }

  public void setL2_commisioner(Location l2_commisioner) {
    this.l2_commisioner = l2_commisioner;
  }

  public Location getL3_rosebank() {
    return l3_rosebank;
  }

  public void setL3_rosebank(Location l3_rosebank) {
    this.l3_rosebank = l3_rosebank;
  }

  public Location getL4_station() {
    return l4_station;
  }

  public void setL4_station(Location l4_station) {
    this.l4_station = l4_station;
  }
  
  public Route getR1() {
    return r1;
  }


  public void setR1(Route r1) {
    this.r1 = r1;
  }


  public Route getR2() {
    return r2;
  }


  public void setR2(Route r2) {
    this.r2 = r2;
  }


  public Route getR3() {
    return r3;
  }


  public void setR3(Route r3) {
    this.r3 = r3;
  }


  public Driver getD1() {
    return d1;
  }


  public void setD1(Driver d1) {
    this.d1 = d1;
  }


  public Driver getD2() {
    return d2;
  }


  public void setD2(Driver d2) {
    this.d2 = d2;
  }


  public Driver getD3() {
    return d3;
  }


  public void setD3(Driver d3) {
    this.d3 = d3;
  }


  public Driver getD4() {
    return d4;
  }


  public void setD4(Driver d4) {
    this.d4 = d4;
  }


  public Driver getD5() {
    return d5;
  }


  public void setD5(Driver d5) {
    this.d5 = d5;
  }


  public Shuttle getS1() {
    return s1;
  }


  public void setS1(Shuttle s1) {
    this.s1 = s1;
  }


  public Shuttle getS2() {
    return s2;
  }


  public void setS2(Shuttle s2) {
    this.s2 = s2;
  }


  public Shuttle getS3() {
    return s3;
  }


  public void setS3(Shuttle s3) {
    this.s3 = s3;
  }


  public Shuttle getS4() {
    return s4;
  }


  public void setS4(Shuttle s4) {
    this.s4 = s4;
  }


  public Shuttle getS5() {
    return s5;
  }


  public void setS5(Shuttle s5) {
    this.s5 = s5;
  }


  public LocationInstance getSp1() {
    return sp1;
  }


  public void setSp1(LocationInstance sp1) {
    this.sp1 = sp1;
  }


  public LocationInstance getSp2() {
    return sp2;
  }


  public void setSp2(LocationInstance sp2) {
    this.sp2 = sp2;
  }


  public LocationInstance getSp3() {
    return sp3;
  }


  public void setSp3(LocationInstance sp3) {
    this.sp3 = sp3;
  }


  public LocationInstance getSp4() {
    return sp4;
  }


  public void setSp4(LocationInstance sp4) {
    this.sp4 = sp4;
  }


  public LocationInstance getSp5() {
    return sp5;
  }


  public void setSp5(LocationInstance sp5) {
    this.sp5 = sp5;
  }


  public AtomicLong getCounter() {
    return counter;
  }
}
